package com.tarena.lbs.stock.web.repository.impl;

import com.tarena.lbs.pojo.stock.bo.CouponStockBO;
import com.tarena.lbs.pojo.stock.dos.CouponStockDO;
import com.tarena.lbs.pojo.stock.param.CouponStockParam;
import com.tarena.lbs.stock.web.converter.CouponStockConverter;
import com.tarena.lbs.stock.web.mapper.CouponStockMapper;
import com.tarena.lbs.stock.web.repository.CouponStockRepository;
import java.util.Date;
import javax.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
public class CouponStockRepositoryImpl implements CouponStockRepository {

    @Resource
    private CouponStockConverter couponStockConverter;

    @Resource
    private CouponStockMapper couponStockMapper;

    @Override
    public void insert(CouponStockParam couponStockParam) {
        CouponStockDO couponStockDO = new CouponStockDO();
        BeanUtils.copyProperties(couponStockParam,couponStockDO);
        couponStockDO.setCreateAt(new Date());
        couponStockMapper.insert(couponStockDO);
    }

    @Override
    public void update(CouponStockParam couponStockParam) {
        CouponStockDO couponStockDO = new CouponStockDO();
        BeanUtils.copyProperties(couponStockParam,couponStockDO);
        couponStockDO.setUpdateAt(new Date());
        couponStockMapper.updateByCouponId(couponStockDO);
    }


    @Override
    public CouponStockBO getDetail(Integer couponId) {
        CouponStockDO couponStockDO = couponStockMapper.selectByCouponId(couponId);
        return couponStockConverter.do2bo(couponStockDO);
    }

}
